import Vuex from 'vuex';
// import api from 'API';
import api from '../stream/index';
import home from './home';
import category from './category';

if (WXEnvironment.platform !== 'Web') {
  Vue.use(Vuex);
}

let store = new Vuex.Store({
  state: {
    tabBarData: []
  },
  mutations: {
    updateTabBarData(state, data) {
      state.tabBarData = data;
    }
  },
  actions: {
    getTabBarData({
      state,
      commit,
      rootState
    }, option) {
      return new Promise((resolve, reject) => {
        api.tabCfg.post(option).then((data) => {
          // console.log(data);
          commit('updateTabBarData', data.data.tab_config);
          resolve(data.data.tab_config);
        }, (error) => {
          console.log(error);
          reject(data.data);
        });
      });
    }
  },
  modules: {
    home,
    category
  }
});

export default store;